/**
 * 用户地址模块接口文件
 */

import axios from './request';

/**
 * 用户地址接口
 */
export interface IUserAddress {
    id: number;
    zip_code: string;
    phone: string;
    province: string;
    city: string;
    district: string;
    address: string;
    default: boolean;
    user_id: number;
}

/**
 * 添加类型
 */
export type AddType = Omit<IUserAddress, 'id'>;

/**
 * 修改类型
 */
export type UpdateType = Omit<IUserAddress, 'user_id'>;

/**
 * 省接口
 */
export interface IProvince {
    id: number;
    province_code: string;
    province: string;
}

/**
 * 市接口
 */
export interface ICity {
    id: number;
    city_code: string;
    city: string;
    p_code: string;
}

/**
 * 区接口
 */
export interface IArea {
    id: number;
    area_code: string;
    area: string;
    p_code: string;
}

/**
 * 省市区接口
 */
export interface IPCD {
    province: IProvince[];
    city: ICity[];
    area: IArea[];
}

/**
 * 获取所有用户地址
 * @returns 
 */
export const getAll = async (id: string): Promise<IUserAddress[]> => axios.get('/users_address/all/' + id);

/**
 * 添加
 * @param model 
 * @returns 
 */
export const add = async (model: AddType) => axios.post('/users_address/add', model);

/**
 * 修改
 * @param model 
 * @returns 
 */
export const update = async (model: UpdateType) => axios.put('/users_address/update', model);

/**
 * 删除用户地址
 * @param id 
 * @returns 
 */
export const deleteAddress = async (id: number) => axios.delete('/users_address/delete/' + id);

/**
 * 获取省市区
 * @returns 
 */
export const getPCD = async (): Promise<IPCD> => axios.get('/users_address/pcd');